package com.example.smart.ui.activity.login

import com.example.lib.extend.setOnDoubleClickListener
import com.example.lib.extend.stringText
import com.example.lib.utils.ToastUtils
import com.example.lib.utils.am.ActManger
import com.example.lib.utils.sp.SpKey
import com.example.lib.utils.sp.SpUtils
import com.example.lib.utils.statusbar.StatusBarUtils
import com.example.smart.R
import com.example.smart.base.ui.activity.BaseActivity
import com.example.smart.databinding.ActivityAccountLoginBinding
import com.example.smart.utils.DisplayUtils
import java.util.Timer
import kotlin.concurrent.timerTask

class AccountLoginActivity : BaseActivity<ActivityAccountLoginBinding>() {

    override fun layoutID() = R.layout.activity_account_login

    override fun initView() {
        StatusBarUtils.setStateAndNavigationBar(this@AccountLoginActivity,
            statusBarColor = com.example.lib.R.color.translate)
    }

    override fun initListener() {
        binding.Login.setOnDoubleClickListener {
            val account = binding.Account.stringText()
            val pass = binding.Password.stringText()
            if (account.isEmpty()) {
                ToastUtils.showToast(getString(R.string.please_input_account))
                return@setOnDoubleClickListener
            }
            if (pass.isEmpty()) {
                ToastUtils.showToast(getString(R.string.please_input_password))
                return@setOnDoubleClickListener
            }

            showLoading(getString(R.string.logging))
            SpUtils.putBoolean(SpKey.IS_LOGIN, true)
            Timer().schedule(timerTask {
                runOnUiThread {
                    hideLoading()
                    ActManger.finishActivity(LoginChooseActivity::class.java)
                    DisplayUtils.toMain(this@AccountLoginActivity)
                }
            }, 2000)
        }
    }
}